package com.homedo.odin.solution.service;

import com.homedo.core.common.base.service.BaseService;
import com.homedo.odin.solution.dao.UserPopularityDetailMapper;
import com.homedo.odin.solution.model.entity.UserPopularityDetail;
import org.springframework.stereotype.Service;

/**
 * <p> 人气明细表 服务实现类 </p>
 *
 * @author HarveyDing
 * @since 2018-03-08
 */
@Service
public class UserPopularityDetailServiceImpl extends BaseService<UserPopularityDetailMapper, UserPopularityDetail> {

    /**
     * 根据用户id和类型获取某种方式增加人气次数
     */
    public Integer selectCountByType(Integer userId, Integer type) {
        return baseMapper.selectCountByType(userId, type);
    }

    /**
     * 根据用户id、日期和类型获取某种方式增加人气次数
     */
    public Integer selectCountByTypeAndDate(Integer userId, Integer type, String date) {
        return baseMapper.selectCountByTypeAndDate(userId, type, date);
    }

    /**
     * 获取用户总人气值
     */
    public Integer selectScoreCountByUserId(Integer userId) {
        return baseMapper.selectScoreCountByUserId(userId);
    }

    /**
     * 插入明细
     */
    public void insert(Integer operationId, Integer targetId, Integer type, Integer score) {
        UserPopularityDetail detail = new UserPopularityDetail();
        detail.setCreatedBy(operationId);
        detail.setModifiedBy(operationId);
        detail.setScore(score);
        detail.setVisitorId(operationId);
        detail.setVisitType(type);
        detail.setUserId(targetId);
        baseMapper.insert(detail);
    }
}
